<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>清除浮动</title>
  <style>
    .box {
      width: 500px;
      border: 1px solid #000;
      /* 创建BFC清除浮动 */
      /* display: inline-block; */
    }

    .item-left {
      width: 100px;
      height: 100px;
      float: left;
      background: red;
      text-align: center;
      line-height: 100px;
    }

    .item-right {
      width: 100px;
      height: 100px;
      float: right;
      background: red;
      text-align: center;
      line-height: 100px;
    }

    /* 利用clear清除浮动 */
    /* .clear {
      clear: both;
    } */
    .box::after {
      content: '';
      clear: both;
      display: block;
    }
  </style>
</head>

<body>
  <div class="box">
    <div class="item-left">float</div>
    <div class="item-right">float</div>
    <!-- <div class="clear"></div> -->
  </div>
</body>

</html>